<template>
<form>

  <el-container>
  <el-header>后台管理系统</el-header>
  <el-container>
    <el-aside width="200px">
        <el-menu
      default-active="2"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b">
      <el-submenu index="1">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>员工管理</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="1-1" @click="dialogFormVisible=true">员工添加</el-menu-item>
          <el-menu-item index="1-2">员工权限</el-menu-item>
        </el-menu-item-group>
      </el-submenu>
      <el-menu-item index="2">
        <i class="el-icon-menu"></i>
        <span slot="title">课程管理</span>
      </el-menu-item>
    </el-menu>
    </el-aside>
    <el-main>
        <el-table
    :data="tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))"
    style="width: 100%">
    <el-table-column
      label="员工号"
      prop="eid">
    </el-table-column>
    <el-table-column
      label="姓名"
      prop="ename">
    </el-table-column>

    <el-table-column
      label="性别">
      <template slot-scope="scope">
      <span v-if="scope.row.sex=='1'">男</span>
      <span v-if="scope.row.sex=='2'">女</span>
      </template>
    </el-table-column>
    
    <el-table-column
      label="地址"
      prop="address">
    </el-table-column>
    <el-table-column
      label="生日"
      prop="birthday">
    </el-table-column>
    <el-table-column
      align="right">
      <template slot="header" slot-scope="scope">
        <el-input
          v-model="searchMap"
          size="mini"
          placeholder="输入关键字搜索" />
          <input type="button" value="搜索" @click="findAll()">
      </template>
      <template slot-scope="scope">
        <el-button
          size="mini"
          type="warning"
          @click="findByEid(scope.$index, scope.row)">修改</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row.id)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
    </el-main>
  </el-container>
</el-container>


<!-- 添加 -->
<el-dialog :visible.sync="dialogFormVisible">
      <el-form  ref="ruleForm" label-width="100px" class="demo-pojo">
  <el-form-item label="员工姓名" prop="ename">
    <el-input v-model="pojo.ename"></el-input>
  </el-form-item>
  <el-form-item label="员工性别">
    <el-radio-group v-model="pojo.sex">
      <el-radio label="1"  >男</el-radio>
      <el-radio label="2"  >女</el-radio>
    </el-radio-group>
  </el-form-item>
  <el-form-item label="家庭住址" prop="desc">
    <el-input type="textarea" v-model="pojo.address"></el-input>
  </el-form-item>
  <el-form-item label="员工生日" required>
    <el-col :span="11">
      <el-form-item prop="date1">
        <el-date-picker type="date" placeholder="选择日期" v-model="pojo.birthday" style="width: 100%;"></el-date-picker>
      </el-form-item>
    </el-col>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm()">立即创建</el-button>
    <el-button @click="dialogFormVisible=false">重置</el-button>
  </el-form-item>
</el-form>
</el-dialog>



<!-- 修改 -->
<el-dialog :model="emp" :visible.sync="dialogFormEdit">
      <el-form  ref="ruleForm" label-width="100px" class="demo-pojo">
        <input type="hidden" v-model="emp.id" name="eid">
  <el-form-item label="员工姓名" prop="ename">
    <el-input v-model="emp.ename"></el-input>
  </el-form-item>
  <el-form-item label="员工性别">
    <el-radio-group v-model="emp.sex">
      <el-radio label="1"  >男</el-radio>
      <el-radio label="2"  >女</el-radio>
    </el-radio-group>
  </el-form-item>
  <el-form-item label="家庭住址" prop="desc">
    <el-input type="textarea" v-model="emp.address"></el-input>
  </el-form-item>
  <el-form-item label="员工生日" required>
    <el-col :span="11">
      <el-form-item prop="date1">
        <el-date-picker type="date" placeholder="选择日期" v-model="emp.birthday" style="width: 100%;"></el-date-picker>
      </el-form-item>
    </el-col>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="updateEmp()">立即修改</el-button>
    <el-button @click="dialogFormEdit=false">重置</el-button>
  </el-form-item>
</el-form>
</el-dialog>





</form>





</template>
<script>
export default {
    name: "index",
    data() {
      return {
          pojo:{},
          emp:{
            id:"",
            ename:"",
            sex:"",
            address:"",
            birthday:""
          },
          tableData: [],
         searchMap:"",
        dialogFormVisible:false,
        dialogFormEdit:false,
        search:""
    
      };
    },
    created(){
    this.findAll()
  },
    methods: {
      submitForm() {
           this.axios.post('http://localhost:8181/emp/add',this.pojo).then(
          res=>{
          this.dialogFormVisible=false
           this.findAll()
          }
        ) 
          },
          updateEmp() {
           this.axios.post('http://localhost:8181/emp/update',this.emp).then(
          res=>{
          this.dialogFormEdit=false
           this.findAll()
          }
        ) 
          },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
       handleOpen(key, keyPath) {
        console.log(key, keyPath);
      },
      handleClose(key, keyPath) {
        console.log(key, keyPath);
        },
      findByEid(index, row) {
        this.dialogFormEdit=true
        this.axios.get('http://localhost:8181/emp/findByEid?id='+row.id).then(
          res=>{
            this.emp=res.data
          }
        )
      },
      handleDelete(index, row) {
        this.axios.get('http://localhost:8181/emp/delete?id='+row).then(
          res=>{
            this.findAll()
        
          }
        )
      },
      findAll(){
        this.axios.get('http://localhost:8181/emp/findAll?searchMap='+this.searchMap).then(
          res=>{
            this.tableData=res.data
          
          }
        )
      }
      
    }
     
    
}
</script>
<style scoped>
.el-container{
    height: 920px;
}
.el-header, .el-footer {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
  }
  
  .el-aside {
    background-color: #545c64;
    color: #333;
    text-align: center;
    line-height: 200px;
  }
  
  .el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    line-height: 10px;
  }
  
  body > .el-container {
    margin-bottom: 40px;
  }
  
  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }
  
  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }
</style>